package net.lummox.command;

import java.util.List;

import net.lummox.common.RequestedAction;
import net.lummox.common.TurnAction;
import net.lummox.common.util.RandomGen;
import net.lummox.model.Turn;

public class CommandSayWord extends CommandImpl {

	@Override
	public Turn execute(Turn turn) {
		List<String> words = aiDao.getWordsLike(turn.getOpponentPartOfWord());
		if (words.size() == 0) {
			turn.setPartOfWord("");
			turn.setAction(TurnAction.BLUFF_FAILED);
		} else {
			int wordIndex = RandomGen.getInt(words.size());
			String word = words.get(wordIndex);
			turn.setPartOfWord(word);
			turn.setAction(TurnAction.WORD_ANSWERED);
		}
		return turn;
	}

	@Override
	public String getName() {
		return RequestedAction.SAY_WORD.name();
	}

}